package com.hursing.tractor.view;

import java.util.ListIterator;

import android.graphics.Rect;

import com.hursing.tractor.baseview.UIView;

public final class UIPlayPanelView extends UIView {

	@Override
	public UIView layout(int w, int h) {
		final int top = (int) (h * 0.54);
		final int bottom = (int) (h * 0.63);
		final int buttonGap = (int) (w * 0.02);
		Rect panelFrame = new Rect(0, top, 0, bottom);
		int panelWidth = 0;
		ListIterator<UIView> itor = subviews().listIterator();
		while (itor.hasNext()) {
			panelWidth += itor.next().frame(new Rect(panelFrame)).measureWidth();
		}
		panelWidth += buttonGap * (subviews().size() - 1);
		
		panelFrame.left = (w - panelWidth) / 2;
		panelFrame.right = panelFrame.left + panelWidth;
		mFrame = panelFrame;
		
		int right = panelFrame.right;
		while (itor.hasPrevious()) {
			UIView view = itor.previous();
			Rect frame = view.frame();
			frame.right = right;
			frame.left = right - view.measureWidth();
			right = frame.left - buttonGap;
		}
		
		return this;
	}
}
